home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / Rect.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  2.4 KB  |  90 lines

  1. package symantec.itools.awt.shape;
  2.  
  3.  
  4. import java.awt.Graphics;
  5. import java.awt.Color;
  6.  
  7.  
  8. /**
  9.  * This class forms the Rectangle shape component.
  10.  * @see symantec.itools.awt.shape.HorizontalLine
  11.  * @see symantec.itools.awt.shape.Square
  12.  * @see symantec.itools.awt.shape.VerticalLine
  13.  * @version 1.0, Nov 26, 1996
  14.  * @author Symantec
  15.  */
  16.  
  17. public class Rect
  18.     extends Shape
  19. {
  20.     /**
  21.      * Constructs a default Rectangle.
  22.      */
  23.     public Rect()
  24.     {
  25.     }
  26.  
  27.     /**
  28.      * Paints the rectangle using the given graphics context.
  29.      * This is a standard Java AWT method which typically gets called
  30.      * by the AWT to handle painting this component. It paints this component
  31.      * using the given graphics context. The graphics context clipping region
  32.      * is set to the bounding rectangle of this component and its <0,0>
  33.      * coordinate is this component's top-left corner.
  34.      *
  35.      * @param g the graphics context used for painting
  36.      * @see java.awt.Component#repaint
  37.      * @see java.awt.Component#update
  38.      */
  39.     public void paint(Graphics g)
  40.     {
  41.         g.clipRect(0, 0, width, height);
  42.  
  43.         int w = width - 1, h = height - 1;
  44.  
  45.         switch (style) {
  46.  
  47.             case BEVEL_LINE :
  48.             default :
  49.                 if (fill) {
  50.                     g.setColor(fillColor);
  51.                     g.fillRect(0, 0, w, h);
  52.                 }
  53.                 else
  54.                     g.drawRect(0, 0, w, h);
  55.                 break;
  56.  
  57.             case BEVEL_LOWERED :
  58.                 g.setColor(Color.gray);
  59.                 g.drawLine(0, h, 0, 0);
  60.                 g.drawLine(0, 0, w, 0);
  61.  
  62.                 g.setColor(Color.white);
  63.                 g.drawLine(w, 0, w, h);
  64.                 g.drawLine(w, h, 0, h);
  65.  
  66.                 if (fill) {
  67.                     g.setColor(fillColor);
  68.                     g.fillRect(1, 1, w - 1, h - 1);
  69.                 }
  70.                 break;
  71.  
  72.             case BEVEL_RAISED :
  73.                 g.setColor(Color.white);
  74.                 g.drawLine(0, h, 0, 0);
  75.                 g.drawLine(0, 0, w, 0);
  76.  
  77.                 g.setColor(Color.gray);
  78.                 g.drawLine(w, 0, w, h);
  79.                 g.drawLine(w, h, 0, h);
  80.  
  81.                 if (fill) {
  82.                     g.setColor(fillColor);
  83.                     g.fillRect(1, 1, w - 1, h - 1);
  84.                 }
  85.                 break;
  86.         }
  87.     }
  88. }
  89.  
  90.